package com.lagou.edu.boot;

import com.lagou.edu.component.TPMonitorThread;
import com.lagou.edu.service.MonitorService;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @program: stage-3-module-3
 * @description:
 * @author: zhangxiaoyang
 * @date: 2020-09-01 05:42
 **/
public class ConsumerApplication {

    public static ExecutorService executor = Executors.newFixedThreadPool(10);

    public static void main(String[] args) throws InterruptedException {
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("dubbo-consumer.xml");
        applicationContext.start();
        MonitorService monitorService = applicationContext.getBean(MonitorService.class);
        new TPMonitorThread();
        long start = System.currentTimeMillis();
        while (System.currentTimeMillis() - start <= 3 * 60 * 1000) {
            executor.execute(() -> {
                String monitorA = null;
                try {
                    monitorA = monitorService.monitorA("monitorA");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.out.println(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss") + ">>>>>>>>>>" + monitorA);
            });
            executor.execute(() -> {
                String monitorB = null;
                try {
                    monitorB = monitorService.monitorB("monitorB");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.out.println(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss") + ">>>>>>>>>>" + monitorB);
            });
            executor.execute(() -> {
                String monitorC = null;
                try {
                    monitorC = monitorService.monitorC("monitorC");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.out.println(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss") + ">>>>>>>>>>" + monitorC);
            });
            Thread.sleep(50);
        }
    }

}
